package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.dto.PurchaseDTO;
import net.wanho.dto.PurchaseaddDTO;
import net.wanho.service.PurchaseService;
import net.wanho.vo.AjaxResult;
import net.wanho.vo.BuyListVo;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/purchase")
public class PurchaseController {

    private final PurchaseService  purchaseService;

    @GetMapping("/purchase-page-list")
    public AjaxResult purchasePageList(@RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "5") Integer pageSize,
                                       PurchaseDTO purchaseDTO) {
        return AjaxResult.success(purchaseService.findPageList(pageNum, pageSize, purchaseDTO)) ;

    }

    @PostMapping("/purchase-add")
    public AjaxResult purchaseAdd(@RequestBody PurchaseaddDTO purchaseaddDTO) {
        purchaseService.save(purchaseaddDTO);
        return AjaxResult.success("采购单添加成功！") ;
    }

    @PostMapping("/in-warehouse-record-add")
    public AjaxResult inWarehouseRecordAdd(@RequestBody BuyListVo buyListVo) {
        purchaseService.saverecord(buyListVo);
        return AjaxResult.success("入库单添加成功！") ;
    }
    @DeleteMapping("/purchase-delete/{id}")
    public AjaxResult purchaseDelete(@PathVariable Integer id) {
        purchaseService.removeById(id);
        return AjaxResult.success("采购单删除成功！") ;
    }

    @PutMapping("/purchase-update")
    public AjaxResult purchaseUpdate(@RequestBody PurchaseaddDTO purchaseaddDTO) {
        purchaseService.update(purchaseaddDTO);
        return AjaxResult.success("采购单修改成功！") ;
    }
}
